<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="__ROOT__/Public/Admin/shortcut icon" href="favicon.ico">
    <link href="__ROOT__/Public/Admin/css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="__ROOT__/Public/Admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__ROOT__/Public/Admin/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="__ROOT__/Public/Admin/css/animate.css" rel="stylesheet">
    <link href="__ROOT__/Public/Admin/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="__ROOT__/Public/Admin/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="__ROOT__/Public/Admin/css/official.css" rel="stylesheet">
    <link href="__ROOT__/Public/Admin/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox float-e-margins">
            <div class="ibox-content">
                <ul class="nav nav-tabs">
                    <li class="active"><a data-toggle="tab" href="#tab-1"><i class="fa fa-list-ol"></i> 选择模板</a>
                    </li>
                </ul>  
                 <form class="well form-search form-inline" method="post" action="">
                    <div class="form-group">
                        <input type="text" class="form-control" name="keyword"  value="{:I('request.keyword/s','')}" placeholder="请输入标识名称">
                    </div>
                    <input type="submit" class="btn btn-primary" value="搜索" /> 
                        &nbsp
                    <a class="edit-user label label-primary" id="{$vo.ID}" onclick="Select('')">不使用模板</a>
                </form>
                <table class="table table-bordered table-striped text-center" data-mobile-responsive="true">
                    <thead id="thead">
                        <tr>
                            <th style="width:10%">合同模板编号</th>
                            <th style="width:15%">标题</th>
                            <th style="width:10%">上传人</th>
                            <th style="width:10%">分类</th>
                            <th style="width:10%">上传时间</th>
                            <th style="width:10%">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        
                        <if condition="count($list) lt 1">
                            <tr> 
                                <td colspan="8" class="text-center">查无数据</td>
                            </tr>
                        <else />
                            <foreach name="list" item="vo">
                                <tr>
                                    <td>{$vo.ID}</td>
                                    <td>{$vo.Title}</td>
                                    <td>{$vo.Author}</td>
                                    <td>{$vo.Name}</td>
                                    <td>{$vo.PubTime}</td>
                                    <td>
                                     <a class="edit-user label label-primary" id="{$vo.ID}" href="<?=U('Admin/ContractTemplate/pdf',array('ID'=>$vo['ID']))?>">查看详情</a>
                                         <a class="edit-user label label-primary" id="{$vo.ID}" onclick="Select({$vo.ID})">点击选择</a>
                                    </td>
                                </tr>
                            </foreach> 
                        </if>
                    </tbody>
                </table>
                {$page}
            </div>
        </div>
    </div>
    <script src="__ROOT__/Public/Admin/js/jquery.js"></script>  
    <script src="__ROOT__/Public/Admin/js/plugins/sweetalert/sweetalert.min.js"></script>
 <script>
 		var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        //选择模板并 遍历
        function Select(id){
            if(id!=''){
        	var ContractID='{:I("ContractID")}'
            var ContractType='{:I("ContractType")}'
        	$.post("{:U('Admin/ContractTemplate/templatec?type=select')}",{'ID':id,'ContractID':ContractID,'ContractType':ContractType},function(result){
        		console.log(result);
                if(result.status) {
                	//console.log(result.info);
                    parent.UE.getEditor('Content').execCommand('cleardoc')
         			parent.UE.getEditor('Content').execCommand('inserthtml', result.info.Content);
         			parent.$('#CTID').val(result.info.ID);
         			parent.$('#CTID_NAME').val(result.info.Title);
         			alert("选择成功");
         			parent.layer.close(index);
         			return false;
                } else {
                    swal("操作失败！", result.info, "error");
                }
            });
        }else{
                    parent.UE.getEditor('Content').execCommand('cleardoc')
                    //parent.UE.getEditor('Content').execCommand('inserthtml', result.info.Content);
                    parent.$('#CTID').val('');
                    parent.$('#CTID_NAME').val('不使用模板');
                    parent.layer.close(index);
        }
        }

		function HtmlDecode(text) {
		   return text.replace(/&/g, '&').replace(/"/g, '\"').replace(/</g, '<').replace(/>/g, '>')
		}


 </script>
</body>
</html>